import socket.CmdMessage;
import socket.CmdMsgType;
import struct.enums.ResourceType;
import struct.ResourceConfig;
import lib4wrapper.WrapperRemoteConnector;

public class ActorDemo1 {
    public static void main(String[] args) {
        ResourceConfig config = new ResourceConfig("Actor1", ResourceType.ACTOR, null);
        WrapperRemoteConnector connector = WrapperRemoteConnector.getInstance();
        if (connector.register("127.0.0.1", 9091, config)) {
            while (true) {
                CmdMessage msg = connector.recv();
                switch (msg.cmd) {
                    case CmdMsgType.ACTION_REQUEST:
                        String cmd = msg.message;
                        System.out.println("Execute command: " + cmd);

                        // execute the command

                        // reply execution result
                        CmdMessage response = new CmdMessage(CmdMsgType.ACTION_BACK, "result");
                        connector.send(response);
                        break;
                    case "action_close":
                        connector.close();
                        return;
                }
            }
        }
    }
}
